<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<title>华胜后台管理</title>
		<link rel="stylesheet" type="text/css" href="css/unified.css">
		<script src="plugins/layui/layui.js"></script>

		<style type="text/css">

		</style>
	</head>

	<body>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>商品库存信息</legend>
			<div class="layui-field-box">
				<table class="layui-table smtable"  id="stockinTable">
					<thead>
						<tr>
							<td style="width: 28px;">操作</td>
							<td>状态</td>
							<td>条码</td>
							<td>名称</td>
							<td>产品图片</td>
							<td>商家编号</td>
							<td>库存地点</td>
							<td>库存数量</td>
							<td>入库数量</td>
						</tr>
					</thead>
					<tbody>
						<!--<tr>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
						<td></td>
					</tr>-->
					</tbody>
					<tfoot>
						<tr>
							<td colspan='100%' id="addtr">点击添加+</td>
						</tr>
					</tfoot>
				</table>
			</div>
		</fieldset>

		<fieldset class="layui-elem-field layui-field-title">
			<legend>入库</legend>
			<div class="layui-field-box">
				<form class="layui-form layui-form-pane IntTable" action="">

					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">批次<span class="layui-badge-dot"></span></label>
						    <div class="layui-input-block">
						      <input type="text" name="batchId" autocomplete="off" placeholder="" class="layui-input inputRequired" value="1">
						    </div>
						 </div>
					</div>
					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">出货点编码<span class="layui-badge-dot"></span></label>
						    <div class="layui-input-block">
						      <input type="text" name="fromLocationId" autocomplete="off" placeholder="" class="layui-input inputRequired" value="1">
						    </div>
						 </div>
					</div>
					
					
					<div class="layui-col-xs12 layui-col-sm6 layui-col-md3">
						<div class="layui-form-item">
						    <label class="layui-form-label">备注</label>
						    <div class="layui-input-block">
						      <input type="text" name="comment" autocomplete="off" placeholder="" class="layui-input">
						    </div>
						 </div>
					</div>
					
				</form>

			</div>
		</fieldset>
		<div class="layui-layer-btn layui-layer-btn-" style="margin-bottom: 35px;">
			<div class="layui-btn yesInsert">确认商品出库</div>
			<!--<div class="layui-btn layui-bg-gray noInsert">取消</div>-->
		</div>
		
		<script id="ComManagement" type="text/html">
			<table class="layui-table " lay-filter="table100" id="cMtable"></table>
		</script>
	</body>

	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="js/allajax.js"></script>
	<script>
		//	$(".stockinTable")
		layui.use(['layer', 'form', 'element', 'table', 'laydate', 'laypage'], function() {
			var layer = layui.layer,
				form = layui.form,
				element = layui.element,
				table = layui.table,
				laydate = layui.laydate,
				laypage = layui.laypage;
				AjaxPostFn('system/bizmerchantinfo/select?page=1&pagesize=10', '{}', function(data) {  	
					//获取商家
					if(data.pageInfo.size != 0) {
						$.each(data.pageInfo.list, function(idx,obj) {
							$("#merchantNumselect").append("<option value='"+obj.merchantNumber+"'>"+obj.merchantName+"</option>");  
						});
						form.render();
						
						
					}else{
						
					}
				})
			
			
			
				
			$("#addtr").click(function() {
				console.log("111")
				var index = layer.open({
					type: 2,
					title: "商品基础信息",
					area: ['100%', '100%'],
					maxmin: true,
					shade: 0,
					content: 'commodity_management.html?urltype=choice&type=new'
				});

			})
			$(".yesInsert").click(function(){
				if($("#stockinTable tbody tr").length != 0 ){
					//选取了商品基础信息
					inputisNull('.inputRequired',function(){
						
						var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
						var injson = $(".IntTable").serializeJson();
						$.each($("#stockinTable tbody tr"), function(idx,obj) {
							var Trstats =  $("#stockinTable tbody tr:eq("+idx+") td:eq(1)").attr("data-stats");
							if(Trstats == 0){

								injson.barCode = $("#stockinTable tbody tr:eq("+idx+") .InBarCode").html();
								injson.createTime = new Date().getTime();
								injson.toLocationId =  $("#stockinTable tbody tr:eq("+idx+") .NowlocationId").html();
								injson.theNum = $("#stockinTable tbody tr:eq("+idx+") .NowtheNum").val();
								injson.NowmerchantNumber = $("#stockinTable tbody tr:eq("+idx+") .NowmerchantNumber").html();
								var thisidx  = idx;
								AjaxPostFn('system/repository/out/insert', JSON.stringify(injson), function(data ) {
								 	console.log(thisidx)
								 	var thistd = $("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)")
								 
//									(function(thisidx){
										if(data.htmlState.status == 200) {
	//										layer.msg("入库成功");
	
											thistd.html("出库成功");
											thistd.css("color","#0db832");
											thistd.attr("data-stats","1");
										}else{
											
	//										layer.msg(data.htmlState.message);
											thistd.html("出库失败");
											thistd.css("color","#ff2d2d");
											thistd.attr("data-stats","2");
										}
										
										 console.log($("#stockinTable tbody tr:eq("+thisidx+") td:eq(1)").html())
//									})(thisidx)
									
									  
									
								} , thisidx);
								
//								AjaxPostFn('system/repository/prepare/insert', JSON.stringify(injson), function(data ) {
//									if(data.htmlState.status == 200) {
//										
//									}
//								})
	//							if(tf){
	//								setTimeout(function(){
	//									parent.layer.close(index)
	//								},1000);
	//							}
								}
							
							 
						});
						
						
//							parent.stockAddlist( 1 , 100 , '{}');
//						
					})
				}else{
					layer.msg("请选择至少一件商品")
				}
				
			
			})
			
			
			
		})
		
		
		function deltr (objidx){
		
			layer.confirm('是否要删除当前选中行信息', function(index){
			  //do something
			  $("#stockinTable tbody tr:eq("+objidx+")").remove();
			  layer.close(index);
			});    
			
		}
	</script>

</html>